module.exports = function ($scope, $resource, $modal, toaster, deleteStr) {
	
	//查询旅行社列表
	$scope.search = function(pageNo){
		var para = {
			'pageNo': pageNo,
			'pageSize': $scope.itemsPerPage,
			'company_name': $scope.searchform.company_name,
			'status': $scope.searchform.status
		}
		$scope.searchform.loading = true;
		$resource('/api/ac/atc/companyService/getAllCompanyList', {}, {}).save(para, function(res){
            if (res.errcode === 0) {
				$scope.companyList = res.data.results;
				$scope.totalItems = res.data.totalRecord;
				$scope.currentPage = pageNo;
				$scope.searchform.loading = false;
            } else {
                toaster.error({title: '', body: res.errmsg});
            }
        });
	}

	init();
	function init(){
		$scope.currentPage = 1;			//当前页码
		$scope.itemsPerPage = 10;		//每页显示几条
		$scope.searchform = {
			'loading': true,
			'status': '',
			'statusList': [
				{'label': '全部', 'value': ''},
				{'label': '未审核', 'value': '0'},
				{'label': '已通过', 'value': '1'},
				{'label': '未通过', 'value': '2'},
			]
		};
		$scope.search(1);
	}

	//查询旅行社详情
	$scope.getInfo = function(info, flag){
		var modalInstance = $modal.open({
			template: require('../views/companyInfo.html'),
			controller: 'companyInfo',
			size: 'lg',
			resolve: {
				company: function () {
					return info;
				},
				flag: function () {
					return flag;
				}
			}
		});
	}

	//添加参加招徕奖励的企业
	$scope.openAstop = function(info, status) {
		var msg = status == '0'?'启用此旅行社继续享受招徕奖励政策?':'停用后此旅行社无法获取后续的招徕奖励政政策';
		if(confirm(msg)){
			var para = {
				'company_code': info.company_code,
				'useable': status
			}
			$resource('/api/ac/atc/companyService/updateStatus', {}, {}).save(para, function(res){
				if (res.errcode === 0) {
					info.useable = status;
					toaster.success({title: '', body: '修改成功'});
				} else {
					toaster.error({title: '', body: '修改失败'});
				}
			});
		}
	}

	//删除已添加的企业
	$scope.delete = function(index, code) {
		if(confirm('确认删除此机构吗？\r\n 删除后无法继续享受招徕奖励政策！')){
			$resource('/api/ac/atc/companyService/deleteCompany', {}, {}).save({'company_code': code}, function(res){
				if (res.errcode === 0) {
					$scope.companyList.splice(index, 1);
					comapnyCodes = deleteStr(comapnyCodes, code);
					toaster.success({title: '', body: '删除成功'});
				} else {
					toaster.error({title: '', body: '删除失败'});
				}
			});
		}
	}


};